'use strict';

module.exports = app => {
  const { router, controller, middleware } = app;
  /**
   * 用户
   */
  // 用户
  router.post('/api/user/wx/login', controller.business.user.wxLogin);
  router.get('/api/user/list', controller.business.user.list);
  router.resources('user', '/api/user', controller.business.user);
  // 地址
  router.get('/api/address/list', controller.business.address.list);
  router.resources('address', '/api/address', controller.business.address);
  /**
   * 订单
   */
  // 产品
  router.get('/api/productCategory/list', controller.business.productCategory.list);
  router.resources('productCategory', '/api/productCategory', controller.business.productCategory);
  // 产品
  router.get('/api/product/list', controller.business.product.list);
  router.resources('product', '/api/product', controller.business.product);
  // 产品规格
  router.get('/api/productSpec/list', controller.business.productSpec.list);
  router.resources('productSpec', '/api/productSpec', controller.business.productSpec);
  // 产品SKU
  router.get('/api/productSku/list', controller.business.productSku.list);
  router.resources('productSku', '/api/productSku', controller.business.productSku);

  // 获取订单详情
  router.get('/api/order/detail', controller.business.order.detail);
  // 取消订单
  router.post('/api/order/cancel', controller.business.order.cancel);
  // 设置订单价格
  router.post('/api/order/price', controller.business.order.setPrice);
  // 申请退款
  router.post('/api/order/refund', controller.business.order.refund);
  router.post('/api/order/refund/confirm', controller.business.order.refundConfirm);
  router.resources('order', '/api/order', controller.business.order);
  // 订单子项
  router.get('/api/orderItem/list', controller.business.orderItem.list);
  router.resources('orderItem', '/api/orderItem', controller.business.orderItem);

  // 支付
  // 创建支付订单
  router.post('/api/payment/wx', controller.payment.wxPay.createPayment);
  // 支付回调
  router.post('/api/wxPay/paymentWxNotify', controller.payment.wxPay.paymentWxNotify);
  router.post('/api/wxPay/refundWxNotify', controller.payment.wxPay.refundWxNotify);
  router.get('/api/decodePayNotify', controller.payment.wxPay.decodePayNotify)
  /**
   * 通用
   */
  // 上传文件
  router.post('/api/upload/file', controller.common.upload.cos);
  router.get('/api/file/list', controller.common.file.list);
  router.resources('file', '/api/file', controller.common.file);
  // 配置
  router.get('/api/config/list', controller.business.config.list);
  router.get('/api/config/key/:key', controller.business.config.getByKey);
  router.resources('config', '/api/config', controller.business.config);
  // banner
  router.get('/api/banner/list', controller.common.banner.list);
  router.resources('banner', '/api/banner', controller.common.banner);
  // 文章
  router.get('/api/article/list', controller.business.article.list);
  router.resources('article', '/api/article', controller.business.article);
  // 通知
  router.get('/api/notice/list', controller.business.notice.list);
  router.resources('notice', '/api/notice', controller.business.notice);

  // ----------------------租户----------------------------//
  // 租户登录/system/auth/login
  router.post('/api/system/auth/login', controller.system.systemUser.login)
  // 获取租户信息和权限
  router.get('/api/system/auth/get-permission-info', middleware.auth(), controller.system.systemUser.getUserInfo)
  router.resources('/api/system/user', middleware.auth(), controller.system.systemUser);
  // 租户菜单
  router.get('/api/system/menu/tree', middleware.auth(), controller.system.systemMenu.tree);
  router.resources('/api/system/menu', middleware.auth(), controller.system.systemMenu);
  // 角色
  router.get('/api/system/role/list', middleware.auth(), controller.system.systemRole.list);
  router.resources('/api/system/role', middleware.auth(), controller.system.systemRole);
  // 权限
  router.get('/api/system/permission/list-user-roles', middleware.auth(), controller.system.systemPermission.getUserRoles);
  router.post('/api/system/permission/assign-user-role', middleware.auth(), controller.system.systemPermission.updateUserRoles);
  router.get('/api/system/permission/list-role-menus', middleware.auth(), controller.system.systemPermission.listRoleMenus);
  router.post('/api/system/permission/assign-role-menu', middleware.auth(), controller.system.systemPermission.updateRoleMenus);
};
